package com.ruoyi.products.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.products.domain.BussDownload;
import com.ruoyi.products.service.IBussDownloadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载记录Controller
 * 
 * @author star
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/products/download")
public class BussDownloadController extends BaseController
{
    @Autowired
    private IBussDownloadService bussDownloadService;

    /**
     * 下载校验次数方法
     */
    @GetMapping("/check/downloadCount")
    public AjaxResult checkDownloadCount(String productsId)
    {
        return bussDownloadService.checkDownloadCount(productsId);
    }

    /**
     * 查询当前用户下载次数
     */
    @GetMapping("/select/downloadCount")
    public AjaxResult getDownloadCount()
    {
        Map data= bussDownloadService.getDownloadCount();
        return success(data);
    }



    /**
     * 查询下载记录列表
     */
    @PreAuthorize("@ss.hasPermi('products:download:list')")
    @GetMapping("/list")
    public TableDataInfo list(BussDownload bussDownload)
    {
        startPage();
        List<BussDownload> list = bussDownloadService.selectBussDownloadList(bussDownload);
        return getDataTable(list);
    }

    /**
     * 导出下载记录列表
     */
    @PreAuthorize("@ss.hasPermi('products:download:export')")
    @Log(title = "下载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BussDownload bussDownload)
    {
        List<BussDownload> list = bussDownloadService.selectBussDownloadList(bussDownload);
        ExcelUtil<BussDownload> util = new ExcelUtil<BussDownload>(BussDownload.class);
        util.exportExcel(response, list, "下载记录数据");
    }

    /**
     * 获取下载记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('products:download:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bussDownloadService.selectBussDownloadById(id));
    }

    /**
     * 新增下载记录
     */
    @PreAuthorize("@ss.hasPermi('products:download:add')")
    @Log(title = "下载记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BussDownload bussDownload)
    {
        return toAjax(bussDownloadService.insertBussDownload(bussDownload));
    }

    /**
     * 修改下载记录
     */
    @PreAuthorize("@ss.hasPermi('products:download:edit')")
    @Log(title = "下载记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BussDownload bussDownload)
    {
        return toAjax(bussDownloadService.updateBussDownload(bussDownload));
    }

    /**
     * 删除下载记录
     */
    @PreAuthorize("@ss.hasPermi('products:download:remove')")
    @Log(title = "下载记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bussDownloadService.deleteBussDownloadByIds(ids));
    }
}
